﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using WebServer.DBUtility;
using WebServer.Models;

namespace WebServer.DBAccess
{
    public class UserDA
    {
        #region 心情逻辑
        /// <summary>
        /// 心情
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public Mood Mood(DateTime Day)
        {
            Mood request = new Mood();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Mood", new object[] { Day }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.Day = reader[1].ToDateTime();
                        else
                            request.Day = DateTime.Now;
                        if (reader[2] != DBNull.Value)
                            request.Up = reader[2].ToInt32();
                        else
                            request.Up = 0;
                        if (reader[3] != DBNull.Value)
                            request.Ping = reader[3].ToInt32();
                        else
                            request.Ping = 0;
                        if (reader[4] != DBNull.Value)
                            request.Down = reader[4].ToInt32();
                        else
                            request.Down = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 心情动作 
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool MoodAction(DateTime Day, string Filed)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Mood_Action", new object[] { Day, Filed }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        #endregion

        #region 分类逻辑
        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<UCate> Cate(bool IsDel)
        {
            List<UCate> request = new List<UCate>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Ctae", new object[] { IsDel }))
                {

                    while (reader.Read())
                    {
                        UCate entity = new UCate();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.IsCompany = reader[2].ToBoolean();
                        else
                            entity.IsCompany = false;
                        if (reader[3] != DBNull.Value)
                            entity.IsLive = reader[3].ToBoolean();
                        else
                            entity.IsLive = false;
                        if (reader[4] != DBNull.Value)
                            entity.IsDel = reader[4].ToBoolean();
                        else
                            entity.IsDel = false;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public UCate CateByID(int ID)
        {
            UCate request = new UCate();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Ctae_ByID", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            request.IsCompany = reader[2].ToBoolean();
                        else
                            request.IsCompany = false;
                        if (reader[3] != DBNull.Value)
                            request.IsLive = reader[3].ToBoolean();
                        else
                            request.IsLive = false;
                        if (reader[4] != DBNull.Value)
                            request.IsDel = reader[4].ToBoolean();
                        else
                            request.IsDel = false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 分类动作 Filed == "IsCompany"  || Filed == "IsLive"  || Filed == "IsDel"
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool CateAction(int ID, string Filed, bool Fn)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Ctae_Action", new object[] { ID, Filed, Fn }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool CateSet(UCate U)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Ctae_Set", new object[] { U.ID, U.Name }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        #endregion

        #region 会员逻辑

        /// <summary>
        /// 普通会员
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Name"></param>
        /// <param name="CateID"></param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<User> UserVip(int PageSize = 10, int PageIndex = 1, string Email = "", string Mobile = "", string Name = "", int CateID = -1, int Order = 0, bool Desc = true, bool IsDel = false)
        {
            List<User> entitys = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (PageIndex - 1) * PageSize, Email, Mobile, Name, CateID, Order, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User]", tiaoj))
                {
                    User request = null;
                    while (reader.Read())
                    {
                        request = new User();
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Email = reader[1].ToString();
                        request.Mobile = reader[2].ToString();
                        request.Name = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            request.Sex = reader[4].ToBoolean();
                        else
                            request.Sex = false;
                        request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                        if (request.CardNO != "" && request.CardNO.Length > 10)
                        {
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { request.CardNO = reader[5].ToString(); }
                        if (reader[6] != DBNull.Value)
                            request.Score = reader[6].ToInt32();
                        else
                            request.Score = 0;
                        request.Introduce = reader[7].ToString();
                        request.Tel = reader[8].ToString();
                        request.Address = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.CateID = reader[11].ToInt32();
                        else
                            request.CateID = 0;
                        if (reader[12] != DBNull.Value)
                            request.IsDel = reader[12].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[13] != DBNull.Value)
                            request.MobileAudit = reader[13].ToBoolean();
                        else
                            request.MobileAudit = false;
                        if (reader[14] != DBNull.Value)
                            request.EmailAudit = reader[14].ToBoolean();
                        else
                            request.EmailAudit = false;
                        if (reader[15] != DBNull.Value)
                            request.IsOpen = reader[15].ToBoolean();
                        else
                            request.IsOpen = false;
                        request.Portrait = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            request.Money = reader[17].ToDecimal();
                        else
                            request.Money = 0;
                        request.QQ = reader[18].ToString();
                        request.WinXin = reader[19].ToString();
                        request.WeiBo = reader[20].ToString();
                        request.OnlogIP = reader[21].ToString();
                        if (reader[22] != DBNull.Value)
                            request.OnlogTime = reader[22].ToDateTime();
                        else
                            request.OnlogTime = DateTime.Now;
                        if (reader[23] != DBNull.Value)
                            request.Hits = reader[23].ToInt32();
                        else
                            request.Hits = 0;
                        request.Company = reader[24].ToString();
                        request.CompanyInfo = reader[25].ToString();
                        request.Province = reader[26].ToString();
                        request.City = reader[27].ToString();
                        request.CateName = reader[28].ToString();
                        entitys.Add(request);
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }

            return entitys;
        }


        /// <summary>
        /// 普通会员总数
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int MUserCount(string Email = "", string Mobile = "", string Name = "", int CateID = -1, bool IsDel = false)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { Email, Mobile, Name, CateID, IsDel };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_User_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 删除会员头像
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int DelUserface(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_User_RemoveP]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 修改用户基本信息
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int UpdateUser(User entity)
        {
            try
            {
                object[] tiaoj = new object[] { entity.ID, entity.Email, entity.Mobile, entity.Name, entity.Sex, entity.CardNO, entity.Score, entity.Introduce, entity.Tel, entity.Address, entity.Money, entity.Company, entity.CompanyInfo, entity.Province, entity.City, entity.QQInfo, entity.QQTeam };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_User_SetInfo]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 处理密码
        /// </summary>
        /// <param name="Pass"></param>
        /// <returns></returns>
        public string CreatePass(string Pass)
        {
            string request = "";
            string frist = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Pass, "MD5");
            for (var i = 0; i < frist.Length; i = i + 8)
            {
                request += System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(frist.Substring(i, 4), "MD5");
            }
            return request;
        }



        /// <summary>
        /// 创建会员
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserInsert(User U)
        {
            int request = 0;
            string Pass = CreatePass(U.Password);
            string Email = string.IsNullOrEmpty(U.Email) ? U.Email : (U.Email == "" ? U.Email : U.Email.ToLower());
            string Mobile = string.IsNullOrEmpty(U.Mobile) ? U.Mobile : (U.Mobile == "" ? U.Mobile : U.Mobile.ToLower());
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_i", new object[] { Email, Mobile, U.Name, Pass }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 创建会员
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserAdd(User U)
        {
            int request = 0;
            string Pass = CreatePass(U.Password);
            string Email = string.IsNullOrEmpty(U.Email) ? U.Email : (U.Email == "" ? U.Email : U.Email.ToLower());
            string Mobile = string.IsNullOrEmpty(U.Mobile) ? U.Mobile : (U.Mobile == "" ? U.Mobile : U.Mobile.ToLower());
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_i", new object[] { Email, Mobile, U.Name, Pass }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public int UpPassword(int UserID,string PassWord)
        {
            int request = 0;
            string Pass = CreatePass(PassWord);
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User_UpPassword]", new object[] { UserID, Pass }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取会员信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public User UserByID(int ID)
        {
            User request = new User();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_ByID", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Email = reader[1].ToString();
                        request.Mobile = reader[2].ToString();
                        request.Name = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            request.Sex = reader[4].ToBoolean();
                        else
                            request.Sex = false;
                        request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                          if (request.CardNO != "" && request.CardNO.Length > 10)
                        {
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { request.CardNO = reader[5].ToString(); }

                        if (reader[6] != DBNull.Value)
                            request.Score = reader[6].ToInt32();
                        else
                            request.Score = 0;
                        request.Introduce = reader[7].ToString();
                        request.Tel = reader[8].ToString();
                        request.Address = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.CateID = reader[11].ToInt32();
                        else
                            request.CateID = 0;
                        if (reader[12] != DBNull.Value)
                            request.IsDel = reader[12].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[13] != DBNull.Value)
                            request.MobileAudit = reader[13].ToBoolean();
                        else
                            request.MobileAudit = false;
                        if (reader[14] != DBNull.Value)
                            request.EmailAudit = reader[14].ToBoolean();
                        else
                            request.EmailAudit = false;
                        if (reader[15] != DBNull.Value)
                            request.IsOpen = reader[15].ToBoolean();
                        else
                            request.IsOpen = false;
                        request.Portrait = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            request.Money = reader[17].ToDecimal();
                        else
                            request.Money = 0;
                        request.QQ = reader[18].ToString();
                        request.WinXin = reader[19].ToString();
                        request.WeiBo = reader[20].ToString();
                        request.OnlogIP = reader[21].ToString();
                        if (reader[22] != DBNull.Value)
                            request.OnlogTime = reader[22].ToDateTime();
                        else
                            request.OnlogTime = DateTime.Now;
                        if (reader[23] != DBNull.Value)
                            request.Hits = reader[23].ToInt32();
                        else
                            request.Hits = 0;
                        request.CateName = reader[24].ToString();
                        if (reader[25] != DBNull.Value)
                            request.FocusNum = reader[25].ToInt32();
                        else
                            request.FocusNum = 0;
                        if (reader[26] != DBNull.Value)
                            request.FansNum = reader[26].ToInt32();
                        else
                            request.FansNum = 0;
                        if (reader[27] != DBNull.Value)
                            request.BarNum = reader[27].ToInt32();
                        else
                            request.BarNum = 0;
                        if (reader[28] != DBNull.Value)
                            request.IsCompany = reader[28].ToBoolean();
                        else
                            request.IsCompany = false;
                        if (reader[29] != DBNull.Value)
                            request.IsLive = reader[29].ToBoolean();
                        else
                            request.IsLive = false;
                        if (reader[30] != DBNull.Value)
                            request.IsExpert = reader[30].ToBoolean();
                        else
                            request.IsExpert = false;
                        if (reader[31] != DBNull.Value)
                            request.BanTrading = reader[31].ToBoolean();
                        else
                            request.BanTrading = false;
                        if (reader[32] != DBNull.Value)
                            request.BanChoose = reader[32].ToBoolean();
                        else
                            request.BanChoose = false;
                        if (reader[33] != DBNull.Value)
                            request.BanFocus = reader[33].ToBoolean();
                        else
                            request.BanFocus = false;
                        request.Company = reader[34].ToString();
                        request.CompanyInfo = reader[35].ToString();
                        request.Province = reader[36].ToString();
                        request.City = reader[37].ToString();
                        if (reader[38] != DBNull.Value)
                            request.UnderlingID = reader[38].ToInt32();
                        else
                            request.UnderlingID = 0;
                        request.Underling = reader[39].ToString();
                        if (reader[40] != DBNull.Value)
                            request.UnderlingState = reader[40].ToInt32();
                        else
                            request.UnderlingState = 0;
                        request.QQInfo = reader[41].ToString();
                        request.QQTeam = reader[42].ToString();
                        request.WebSite = reader[43].ToString();
                        //request.Certificate = reader[44].ToString();
                        if (reader[45] != DBNull.Value)
                            request.LetterNum = reader[45].ToInt32();
                        else
                            request.LetterNum = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 详细的人员信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public UserInfo UserInfoByID(int ID = 0)
        {
            UserInfo request = new UserInfo();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_UserInfo_ByID]", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Email = reader[1].ToString();
                        request.Mobile = reader[2].ToString();
                        request.Name = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            request.Sex = reader[4].ToBoolean();
                        else
                            request.Sex = false;
                        request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                        if (request.CardNO != "" && request.CardNO.Length > 10)
                        {
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { request.CardNO = reader[5].ToString(); }

                        if (reader[6] != DBNull.Value)
                            request.Score = reader[6].ToInt32();
                        else
                            request.Score = 0;
                        request.Introduce = reader[7].ToString();
                        request.Tel = reader[8].ToString();
                        request.Address = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.CateID = reader[11].ToInt32();
                        else
                            request.CateID = 0;
                        if (reader[12] != DBNull.Value)
                            request.IsDel = reader[12].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[13] != DBNull.Value)
                            request.MobileAudit = reader[13].ToBoolean();
                        else
                            request.MobileAudit = false;
                        if (reader[14] != DBNull.Value)
                            request.EmailAudit = reader[14].ToBoolean();
                        else
                            request.EmailAudit = false;
                        if (reader[15] != DBNull.Value)
                            request.IsOpen = reader[15].ToBoolean();
                        else
                            request.IsOpen = false;
                        request.Portrait = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            request.Money = reader[17].ToDecimal();
                        else
                            request.Money = 0;
                        request.QQ = reader[18].ToString();
                        request.WinXin = reader[19].ToString();
                        request.WeiBo = reader[20].ToString();
                        request.OnlogIP = reader[21].ToString();
                        if (reader[22] != DBNull.Value)
                            request.OnlogTime = reader[22].ToDateTime();
                        else
                            request.OnlogTime = DateTime.Now;
                        if (reader[23] != DBNull.Value)
                            request.Hits = reader[23].ToInt32();
                        else
                            request.Hits = 0;
                        request.CateName = reader[24].ToString();
                        if (reader[25] != DBNull.Value)
                            request.FocusNum = reader[25].ToInt32();
                        else
                            request.FocusNum = 0;
                        if (reader[26] != DBNull.Value)
                            request.FansNum = reader[26].ToInt32();
                        else
                            request.FansNum = 0;
                        if (reader[27] != DBNull.Value)
                            request.BarNum = reader[27].ToInt32();
                        else
                            request.BarNum = 0;
                        if (reader[28] != DBNull.Value)
                            request.IsCompany = reader[28].ToBoolean();
                        else
                            request.IsCompany = false;
                        if (reader[29] != DBNull.Value)
                            request.IsLive = reader[29].ToBoolean();
                        else
                            request.IsLive = false;
                        if (reader[30] != DBNull.Value)
                            request.IsExpert = reader[30].ToBoolean();
                        else
                            request.IsExpert = false;
                        if (reader[31] != DBNull.Value)
                            request.BanTrading = reader[31].ToBoolean();
                        else
                            request.BanTrading = false;
                        if (reader[32] != DBNull.Value)
                            request.BanChoose = reader[32].ToBoolean();
                        else
                            request.BanChoose = false;
                        if (reader[33] != DBNull.Value)
                            request.BanFocus = reader[33].ToBoolean();
                        else
                            request.BanFocus = false;
                        request.Company = reader[34].ToString();
                        request.CompanyInfo = reader[35].ToString();
                        request.Province = reader[36].ToString();
                        request.City = reader[37].ToString();
                        if (reader[38] != DBNull.Value)
                            request.UnderlingID = reader[38].ToInt32();
                        else
                            request.UnderlingID = 0;
                        request.Underling = reader[39].ToString();
                        if (reader[40] != DBNull.Value)
                            request.UnderlingState = reader[40].ToInt32();
                        else
                            request.UnderlingState = 0;
                        request.QQInfo = reader[41].ToString();
                        request.QQTeam = reader[42].ToString();
                        request.WebSite = reader[43].ToString();
                        if (reader[44] != DBNull.Value)
                            request.LetterNum = reader[44].ToInt32();
                        else
                            request.LetterNum = 0;
                        //if (reader[45] != DBNull.Value)
                        //    request.Sort = reader[45].ToInt32();
                        //else
                        //    request.Sort = 0;
                        if (reader[46] != DBNull.Value)
                            request.UserID = reader[46].ToInt32();
                        else
                            request.UserID = 0;
                        request.CardImg = reader[47].ToString();
                        if (reader[48] != DBNull.Value)
                            request.IsStore = reader[48].ToBoolean();
                        else
                            request.IsStore = false;
                        request.WeixinInfo = reader[49].ToString();
                        request.WeixinCode = reader[50].ToString();
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 获取会员信息
        /// </summary>
        /// <param name="Name"></param>
        /// <returns></returns>
        public User UserByName(string Name)
        {
            User request = new User();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_ByName", new object[] { Name }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Email = reader[1].ToString();
                        request.Mobile = reader[2].ToString();
                        request.Name = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            request.Sex = reader[4].ToBoolean();
                        else
                            request.Sex = false;
                        request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                        if (request.CardNO != "" && request.CardNO.Length > 10)
                        {
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { request.CardNO = reader[5].ToString(); }
                        if (reader[6] != DBNull.Value)
                            request.Score = reader[6].ToInt32();
                        else
                            request.Score = 0;
                        request.Introduce = reader[7].ToString();
                        request.Tel = reader[8].ToString();
                        request.Address = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.CreateTime = reader[10].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[11] != DBNull.Value)
                            request.CateID = reader[11].ToInt32();
                        else
                            request.CateID = 0;
                        if (reader[12] != DBNull.Value)
                            request.IsDel = reader[12].ToBoolean();
                        else
                            request.IsDel = false;
                        if (reader[13] != DBNull.Value)
                            request.MobileAudit = reader[13].ToBoolean();
                        else
                            request.MobileAudit = false;
                        if (reader[14] != DBNull.Value)
                            request.EmailAudit = reader[14].ToBoolean();
                        else
                            request.EmailAudit = false;
                        if (reader[15] != DBNull.Value)
                            request.IsOpen = reader[15].ToBoolean();
                        else
                            request.IsOpen = false;
                        request.Portrait = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            request.Money = reader[17].ToDecimal();
                        else
                            request.Money = 0;
                        request.QQ = reader[18].ToString();
                        request.WinXin = reader[19].ToString();
                        request.WeiBo = reader[20].ToString();
                        request.OnlogIP = reader[21].ToString();
                        if (reader[22] != DBNull.Value)
                            request.OnlogTime = reader[22].ToDateTime();
                        else
                            request.OnlogTime = DateTime.Now;
                        if (reader[23] != DBNull.Value)
                            request.Hits = reader[23].ToInt32();
                        else
                            request.Hits = 0;
                        request.CateName = reader[24].ToString();
                        if (reader[25] != DBNull.Value)
                            request.FocusNum = reader[25].ToInt32();
                        else
                            request.FocusNum = 0;
                        if (reader[26] != DBNull.Value)
                            request.FansNum = reader[26].ToInt32();
                        else
                            request.FansNum = 0;
                        if (reader[27] != DBNull.Value)
                            request.BarNum = reader[27].ToInt32();
                        else
                            request.BarNum = 0;
                        if (reader[28] != DBNull.Value)
                            request.IsCompany = reader[28].ToBoolean();
                        else
                            request.IsCompany = false;
                        if (reader[29] != DBNull.Value)
                            request.IsLive = reader[29].ToBoolean();
                        else
                            request.IsLive = false;
                        if (reader[30] != DBNull.Value)
                            request.IsExpert = reader[30].ToBoolean();
                        else
                            request.IsExpert = false;
                        if (reader[31] != DBNull.Value)
                            request.BanTrading = reader[31].ToBoolean();
                        else
                            request.BanTrading = false;
                        if (reader[32] != DBNull.Value)
                            request.BanChoose = reader[32].ToBoolean();
                        else
                            request.BanChoose = false;
                        if (reader[33] != DBNull.Value)
                            request.BanFocus = reader[33].ToBoolean();
                        else
                            request.BanFocus = false;
                        request.Company = reader[34].ToString();
                        request.CompanyInfo = reader[35].ToString();
                        request.Province = reader[36].ToString();
                        request.City = reader[37].ToString();
                        if (reader[38] != DBNull.Value)
                            request.UnderlingID = reader[38].ToInt32();
                        else
                            request.UnderlingID = 0;
                        request.Underling = reader[39].ToString();
                        if (reader[40] != DBNull.Value)
                            request.UnderlingState = reader[40].ToInt32();
                        else
                            request.UnderlingState = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 创建会员
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserLogin(string Name, string Pass, bool Fn, string IP)
        {
            int request = 0;
            Pass = CreatePass(Pass);
            Name = string.IsNullOrEmpty(Name) ? Name : (Name == "" ? Name : Name.ToLower());
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Login", new object[] { Name, Pass, Fn, IP }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 存在
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int HasUser(string Name, int Type)
        {
            int request = 0;
            Name = string.IsNullOrEmpty(Name) ? Name : (Name == "" ? Name : Name.ToLower());
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Has", new object[] { Name, Type }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 会员动作 Filed == "IsDel"  || Filed == "EmailAudit"  || Filed == "MobileAudit" || Filed == "IsOpen" 
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Filed"></param>
        /// <param name="Fn"></param>
        /// <returns></returns>
        public int UserAction(int ID, string Filed, bool Fn)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Action", new object[] { ID, Filed, Fn }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 更新会员-动作中有的这里不允许更新
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserSet(UserInfo U)
        {
            int request = -1;

            U.Password = U.Password == "" ? "" : CreatePass(U.Password);

            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Set", new object[] { U.ID, U.CateID, U.Sex, U.CardNO, U.Tel, U.Address, U.Company, U.CompanyInfo, U.Province, U.City, U.Name,U.QQInfo,U.QQTeam,U.WebSite ,U.WeixinInfo,U.WeixinCode,U.CardImg,U.IsStore,U.Password}))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 注册会员时-经济商填写信息
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserBrokerSet(UserBrokerEntity U)
        {
            int request = -1;

            U.Password = U.Password == "" ? "" : CreatePass(U.Password);

            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_SetBroker", new object[] { U.ID, U.CateID, U.Sex, U.CardNO, U.Tel, U.Address, U.Company, U.CompanyInfo, U.Province, U.City, U.Name, U.QQInfo, U.QQTeam, U.WebSite, U.WeixinInfo, U.WeixinCode, U.CardImg, U.IsStore, U.Password, U.Mobile, U.Email, U.RdgisteredCapital, U.Staff, U.BrokerCate }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 查看申请经济商和分析师账号的详细信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public UserBrokerEntity MGetCheckUser(int ID)
        {
            UserBrokerEntity request = new UserBrokerEntity();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_CheckUser_ByIDM]", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.Email = reader[1].ToString();
                        request.Mobile = reader[2].ToString();
                        request.Name = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            request.Sex = reader[4].ToBoolean();
                        else
                            request.Sex = false;
                        request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                        if (request.CardNO != "" && request.CardNO.Length > 10)
                        {
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { request.CardNO = reader[5].ToString(); }

                        if (reader[6] != DBNull.Value)
                            request.Score = reader[6].ToInt32();
                        else
                            request.Score = 0;
                        request.Introduce = reader[7].ToString();
                        request.Tel = reader[8].ToString();
                        request.Address = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            request.MobileAudit = reader[10].ToBoolean();
                        else
                            request.MobileAudit = false;
                        if (reader[11] != DBNull.Value)
                            request.EmailAudit = reader[11].ToBoolean();
                        else
                            request.EmailAudit = false;                    
                        request.Portrait = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            request.Money = reader[13].ToDecimal();
                        else
                            request.Money = 0;
                        if (reader[14] != DBNull.Value)
                            request.Hits = reader[14].ToInt32();
                        else
                            request.Hits = 0;
                        request.CateName = reader[15].ToString();                    
                        request.Company = reader[16].ToString();
                        request.CompanyInfo = reader[17].ToString();
                        request.Province = reader[18].ToString();
                        request.City = reader[19].ToString();                    
                        request.QQInfo = reader[20].ToString();
                        request.QQTeam = reader[21].ToString();
                        request.WebSite = reader[22].ToString();
                        request.WeixinInfo = reader[23].ToString();                 
                        request.CardImg = reader[24].ToString();
                        if (reader[25] != DBNull.Value)
                            request.IsStore = reader[25].ToBoolean();
                        else
                            request.IsStore = false;
                        if (reader[26] != DBNull.Value)
                            request.RdgisteredCapital = reader[26].ToDecimal();
                        else
                            request.RdgisteredCapital = 0;
                        if (reader[27] != DBNull.Value)
                            request.Staff = reader[27].ToInt32();
                        else
                            request.Staff = 0;
                        if (reader[28] != DBNull.Value)
                            request.BrokerCate = reader[28].ToInt32();
                        else
                            request.BrokerCate = 0;
                        if (reader[29] != DBNull.Value)
                            request.CateID = reader[29].ToInt32();
                        else
                            request.CateID = 0;
                        if (reader[30] != DBNull.Value)
                            request.Remark = reader[30].ToString();
                        else
                            request.Remark = "0";
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 新建经济商-动作中有的这里不允许更新
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserApplyBroker(UserInfo U)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_ApplyBroker_Set", new object[] { U.ID, U.Email, U.Mobile, U.Name, U.Password, U.Sex, U.CardNO, U.Tel, U.Address, U.CateID,U.IsDel,U.IsOpen, U.Company, U.CompanyInfo, U.Province, U.City, U.QQInfo, U.QQTeam, U.WebSite, U.WeixinInfo, U.WeixinCode, U.CardImg, U.IsStore }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 更新会员-动作中有的这里不允许更新
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserSetOne(int ID, string Filed, string Value)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_SetOne", new object[] { ID, Filed, Value }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 会员绑定  Filed == "Email"  || Filed == "Mobile" 
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Filed"></param>
        /// <param name="Val"></param>
        /// <returns></returns>
        public int UserBind(string Filed, string Val)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Bind", new object[] { Filed, Val }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 已经绑定过得手机或者邮箱，再绑定邮箱或手机
        /// </summary>
        /// <param name="Filed"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int UserTwoBind(string Filed,string Val, int ID)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Bd", new object[] { Filed, Val, ID }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 创建会员
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int UserPassWord(string Name, string Code, string Pass)
        {
            int request = 0;
            Pass = CreatePass(Pass);
            bool isMail = false;
            if (Name.IndexOf("@") >= 0)
            {
                isMail = true;
            }
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_PassWord", new object[] { Name, Code, Pass, isMail, DateTime.Now }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 微信登录
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int WeiXinLogin(string OpenID, string Province, string City, bool Sex, string Name, string Portrait, string ip)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_WeiXin_Login", new object[] { OpenID, Province, City, Sex, Name, Portrait, ip }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// QQ登录
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int QQLogin(string OpenID, string Province, string City, bool Sex, string Name, string Portrait, string ip)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_QQ_Login", new object[] { OpenID, Province, City, Sex, Name, Portrait, ip }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        /// <summary>
        /// 微博登录
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int WeiboLogin(string OpenID, string Province, string City, bool Sex, string Name, string Portrait, string ip)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Weibo_Login", new object[] { OpenID, Province, City, Sex, Name, Portrait, ip }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 后團管理人員主動幫用戶改類型
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="CateID"></param>
        /// <returns></returns>
        public static int ManageCheckUser(int ID, int CateID)
        {
            try
            {
                object[] whereInfo = new object[] { ID, CateID };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_User_Check]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 绑定处理
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Code"></param>
        /// /// <param name="Type"></param>
        /// <returns></returns>
        public int BoundUser(int UserID, string Name, string Code, bool Type)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_BoundUser", new object[] { UserID, Name, Code, Type, DateTime.Now }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request = reader[0].ToInt32();
                        else
                            request = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 搜索所有的用户
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Name"></param>
        /// <param name="UserID"></param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<UserFocusEntity> UserOrder(int PageSize, int PageIndex, string Email, string Mobile, string Name, int UserID, int Order, bool Desc, bool IsDel)
        {
            List<UserFocusEntity> request = new List<UserFocusEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User_Nor]", new object[] { PageSize,(PageIndex-1)*PageSize,Email,Mobile,Name,UserID,Order,Desc,IsDel }))
                {
                    while (reader.Read())
                    {
                        UserFocusEntity entity = new UserFocusEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.FocusName = reader[1].ToString();
                        entity.Introduce = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.CateID = reader[4].ToInt32();
                        else
                            entity.CateID = 0;
                        if (reader[5] != DBNull.Value)
                            entity.IsOpen = reader[5].ToBoolean();
                        else
                            entity.IsOpen = false;
                        entity.Portrait = reader[6].ToString();
                        if (reader[8] != DBNull.Value)
                            entity.Score = reader[8].ToInt32();
                        else
                            entity.Score = 0;
                        if (reader[9] != DBNull.Value)
                            entity.IfFocus = reader[9].ToInt32();
                        else
                            entity.IfFocus = 0;
                        if (reader[10] != DBNull.Value)
                            entity.FocusNum = reader[10].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[11] != DBNull.Value)
                            entity.FansNum = reader[11].ToInt32();
                        else
                            entity.FansNum = 0;
              
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 判断qq是否被注册过
        /// </summary>
        /// <param name="OpenID"></param>
        /// <returns></returns>
        public User UserByQQID(string OpenID)
        {
         
                User request = new User();
                try
                {
                    SQLHelper sqlHelp = new SQLHelper();
                    using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User_ByOpenID]", new object[] { OpenID }))
                    {

                        while (reader.Read())
                        {
                            if (reader[0] != DBNull.Value)
                                request.ID = reader[0].ToInt32();
                            else
                                request.ID = 0;
                            request.Email = reader[1].ToString();
                            request.Mobile = reader[2].ToString();
                            request.Name = reader[3].ToString();
                            if (reader[4] != DBNull.Value)
                                request.Sex = reader[4].ToBoolean();
                            else
                                request.Sex = false;
                            request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString();
                            if (request.CardNO != "" && request.CardNO.Length > 10)
                            {
                                request.CardNO = reader[5].ToString() == "" ? "" : reader[5].ToString().Substring(0, 8) + "**********";
                            }
                            else
                            { request.CardNO = reader[5].ToString(); }

                            if (reader[6] != DBNull.Value)
                                request.Score = reader[6].ToInt32();
                            else
                                request.Score = 0;
                            request.Introduce = reader[7].ToString();
                            request.Tel = reader[8].ToString();
                            request.Address = reader[9].ToString();
                            if (reader[10] != DBNull.Value)
                                request.CreateTime = reader[10].ToDateTime();
                            else
                                request.CreateTime = DateTime.Now;
                            if (reader[11] != DBNull.Value)
                                request.CateID = reader[11].ToInt32();
                            else
                                request.CateID = 0;
                            if (reader[12] != DBNull.Value)
                                request.IsDel = reader[12].ToBoolean();
                            else
                                request.IsDel = false;
                            if (reader[13] != DBNull.Value)
                                request.MobileAudit = reader[13].ToBoolean();
                            else
                                request.MobileAudit = false;
                            if (reader[14] != DBNull.Value)
                                request.EmailAudit = reader[14].ToBoolean();
                            else
                                request.EmailAudit = false;
                            if (reader[15] != DBNull.Value)
                                request.IsOpen = reader[15].ToBoolean();
                            else
                                request.IsOpen = false;
                            request.Portrait = reader[16].ToString();
                            if (reader[17] != DBNull.Value)
                                request.Money = reader[17].ToDecimal();
                            else
                                request.Money = 0;
                            request.QQ = reader[18].ToString();
                            request.WinXin = reader[19].ToString();
                            request.WeiBo = reader[20].ToString();
                            request.OnlogIP = reader[21].ToString();
                            if (reader[22] != DBNull.Value)
                                request.OnlogTime = reader[22].ToDateTime();
                            else
                                request.OnlogTime = DateTime.Now;
                            if (reader[23] != DBNull.Value)
                                request.Hits = reader[23].ToInt32();
                            else
                                request.Hits = 0;
                            request.CateName = reader[24].ToString();
                            if (reader[25] != DBNull.Value)
                                request.FocusNum = reader[25].ToInt32();
                            else
                                request.FocusNum = 0;
                            if (reader[26] != DBNull.Value)
                                request.FansNum = reader[26].ToInt32();
                            else
                                request.FansNum = 0;
                            if (reader[27] != DBNull.Value)
                                request.BarNum = reader[27].ToInt32();
                            else
                                request.BarNum = 0;
                            if (reader[28] != DBNull.Value)
                                request.IsCompany = reader[28].ToBoolean();
                            else
                                request.IsCompany = false;
                            if (reader[29] != DBNull.Value)
                                request.IsLive = reader[29].ToBoolean();
                            else
                                request.IsLive = false;
                            if (reader[30] != DBNull.Value)
                                request.IsExpert = reader[30].ToBoolean();
                            else
                                request.IsExpert = false;
                            if (reader[31] != DBNull.Value)
                                request.BanTrading = reader[31].ToBoolean();
                            else
                                request.BanTrading = false;
                            if (reader[32] != DBNull.Value)
                                request.BanChoose = reader[32].ToBoolean();
                            else
                                request.BanChoose = false;
                            if (reader[33] != DBNull.Value)
                                request.BanFocus = reader[33].ToBoolean();
                            else
                                request.BanFocus = false;
                            request.Company = reader[34].ToString();
                            request.CompanyInfo = reader[35].ToString();
                            request.Province = reader[36].ToString();
                            request.City = reader[37].ToString();
                            if (reader[38] != DBNull.Value)
                                request.UnderlingID = reader[38].ToInt32();
                            else
                                request.UnderlingID = 0;
                            request.Underling = reader[39].ToString();
                            if (reader[40] != DBNull.Value)
                                request.UnderlingState = reader[40].ToInt32();
                            else
                                request.UnderlingState = 0;
                            request.QQInfo = reader[41].ToString();
                            request.QQTeam = reader[42].ToString();
                            request.WebSite = reader[43].ToString();
                            //request.Certificate = reader[44].ToString();
                            if (reader[45] != DBNull.Value)
                                request.LetterNum = reader[45].ToInt32();
                            else
                                request.LetterNum = 0;
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                   
                }
                return request;
        }
        #endregion

        #region 审核分析师，经济商
        /// <summary>
        /// 审核分析师，经济商
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="CateName"></param>
        /// <param name="Name"></param>
        /// <param name="Tel"></param>
        /// <param name="Email"></param>
        /// <param name="Address">可以模糊查询</param>
        /// <param name="QQInfo"></param>
        /// <param name="CheckCode"></param>
        /// <param name="Order">默认为时间排序，1-是否审核，2-地址</param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<CheckUser> CheckUserList(int PageSize = 8, int PageIndex = 1, string CateName = "", string Name = "", string Tel = "", string Email = "", string Address = "", string QQInfo = "", string CheckCode = "", int Order = 0, bool Desc = true, bool IsDel = false)
        {
            List<CheckUser> entitys = new List<CheckUser>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (PageIndex - 1) * PageSize, CateName, Name, Tel, Email, Address, QQInfo, CheckCode, Order, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_CheckUser_Q]", tiaoj))
                {
                    CheckUser entity = null;
                    while (reader.Read())
                    {
                        entity = new CheckUser();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.UserID = reader[2].ToInt32();
                        else
                            entity.UserID = 0;
                        entity.Name = reader[3].ToString();
                        entity.Tel = reader[4].ToString();
                        entity.Email = reader[5].ToString();
                        entity.Address = reader[6].ToString();
                        entity.QQInfo = reader[7].ToString();
                        entity.CheckCode = reader[8].ToString();
                        entity.Remark = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                        {
                            entity.IsOpen = reader[10].ToBoolean();
                        }
                        else
                        {
                            entity.IsOpen = false;
                        }
                        if (reader[11] != DBNull.Value)
                        {
                            entity.IsDel = reader[11].ToBoolean();
                        }
                        else
                        {
                            entity.IsDel = false;
                        }
                        if (reader[12] != DBNull.Value)
                            entity.CreateTime = reader[12].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Mobile = reader[13].ToString();

                        entitys.Add(entity);
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }

            return entitys;
        }

        /// <summary>
        /// 审核分析师，经济商总数.
        /// </summary>
        /// <param name="CateName"></param>
        /// <param name="Name"></param>
        /// <param name="Tel"></param>
        /// <param name="Email"></param>
        /// <param name="Address"></param>
        /// <param name="QQInfo"></param>
        /// <param name="CheckCode"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static int CheckUserCount(string CateName = "", string Name = "", string Tel = "", string Email = "", string Address = "", string QQInfo = "", string CheckCode = "",  bool IsDel = false)
        {
            try
            {
                object[] tiaoj = new object[] {  CateName, Name, Tel, Email, Address, QQInfo, CheckCode,IsDel };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_CheckUser_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsOpen"></param>
        /// <returns></returns>
        public static string CheckUser(int ID = 0, bool IsOpen = false)
        {
            try
            {
                object[] whereInfo = new object[] { ID, IsOpen };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_CheckUser_Action]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return obj.ToString();
                }
                else
                    return "-1";
            }
            catch (Exception ex)
            {
                return "-1";
            }
        }

        /// <summary>
        /// 根据Id获取申请人的详细信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static User CheckUserByID(int ID = 0)
        {
            User entity = new User();
            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_CheckUser_ByID]", ID))
                {
                    while (reader.Read())
                    {

                        entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.CheckID = reader[0].ToInt32();
                        else
                            entity.CheckID = 0;
                        entity.CateName = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.ID = reader[2].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[3].ToString();
                        entity.Tel = reader[4].ToString();
                        entity.Email = reader[5].ToString();
                        entity.Address = reader[6].ToString();
                        entity.QQ = reader[7].ToString();
                        entity.CardNO = reader[8].ToString() == "" ? "" : reader[8].ToString();
                        if (entity.CardNO != "" && entity.CardNO.Length > 10)
                        {
                            entity.CardNO = reader[8].ToString() == "" ? "" : reader[8].ToString().Substring(0, 8) + "**********";
                        }
                        else
                        { entity.CardNO = reader[8].ToString(); }
                        entity.Remark = reader[9].ToString();
                        //entity.IsOpen=
                        //entity.IsDel
                        if (reader[12] != DBNull.Value)
                            entity.CheckCreateTime = reader[12].ToDateTime();
                        else
                            entity.CheckCreateTime = DateTime.Now;

                        entity.Mobile = reader[13].ToString();
                        entity.Sex = reader[14].ToBoolean();
                        if (reader[15] != DBNull.Value)
                            entity.Score = reader[15].ToInt32();
                        else
                            entity.Score = 0;
                        entity.Introduce = reader[16].ToString();
                        entity.Portrait = reader[17].ToString();
                        entity.Money = reader[18].ToDecimal();
                        if (reader[19] != DBNull.Value)
                            entity.Hits = reader[19].ToInt32();
                        else
                            entity.Hits = 0;
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entity;
        }



        /// <summary>
        /// 审核不通过，添加原因
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Remark"></param>
        /// <returns></returns>
        public static int AddRemark(int ID = 0, string Remark = "")
        {
            try
            {
                object[] whereInfo = new object[] { ID, Remark };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_CheckUser_Addreason]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 创建审核
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int CheckInsert(CheckUser U)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Check_i", new object[] { U.UserID, Convert.ToInt32(U.CateName), U.Name, U.Mobile, U.Tel, U.QQInfo, U.Email, U.Address, U.CheckCode }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 后台添加经济商
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int BrokerSet(User entity)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User_AddBroker]", new object[] { entity.ID, entity.Email, entity.Mobile, entity.Name, entity.Password, entity.Sex, entity.CardNO, entity.Score, entity.Introduce, entity.Tel, entity.Address, entity.EmailAudit, entity.MobileAudit, entity.Company, entity.CompanyInfo, entity.Province, entity.City, entity.QQInfo, entity.QQTeam, entity.WebSite, entity.WeixinInfo, entity.WeixinCode, entity.IsStore, entity.CardImg }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 后台审核经济商申请入驻
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="UserName"></param>
        /// <param name="Province"></param>
        /// <param name="City"></param>
        /// <param name="IsOpen"></param>
        /// <param name="CateID"></param>
        /// <param name="OrderID"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<OpenBourkerEntity> OpenBourkerList(int PageSize, int PageIndex, string UserName, string Province, string City, int IsOpen, int CateID, int OrderID , bool Desc, int IsDel)
        {
            List<OpenBourkerEntity> entitys = new List<OpenBourkerEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { PageSize, (PageIndex - 1) * PageSize, UserName, Province, City, IsOpen, CateID, OrderID, Desc, IsDel };
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_UserInfo_MQ]", tiaoj))
                {
                    OpenBourkerEntity entity = null;
                    while (reader.Read())
                    {
                        entity = new OpenBourkerEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Email = reader[1].ToString();
                        entity.Name = reader[2].ToString();
                        entity.Company = reader[3].ToString();
                        entity.Mobile = reader[4].ToString();
                        entity.Province = reader[5].ToString();
                        entity.City = reader[6].ToString();
                        entity.Address = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            entity.IsStore = reader[8].ToBoolean();
                        else
                            entity.IsStore = false;
                        entity.CardImg = reader[9].ToString();                       

                        entitys.Add(entity);
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }

            return entitys;
           
        }


        /// <summary>
        /// 后台审核经济商申请入驻
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int OpenBourkerCount(string UserName, string Province, string City, int IsOpen, int CateID, int IsDel)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_UserInfo_MC]", new object[] { UserName, Province, City, IsOpen, CateID,  IsDel }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 审核成功
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public int OpenBroKerSu(int UserID)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_User_OpenBourker]", new object[] { UserID }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion

        #region 公司逻辑
        /// <summary>
        /// 创建公司
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int CompanyInsert(CompanyEntity U)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Company_i", new object[] { U.UserID, U.Name, U.Province, U.City, U.Address, U.Map, U.Introduce, U.Url, U.Tel, U.Email, U.Aptitude, U.Portrait }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 公司动作 Filed == "IsDel"  || Filed == "Audit"
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Filed"></param>
        /// <param name="Fn"></param>
        /// <returns></returns>
        public int CompanyAction(int ID, string Filed, bool Fn)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Company_Action", new object[] { ID, Filed, Fn }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 公司动作 Filed == "IsDel"  || Filed == "Audit"
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Filed"></param>
        /// <param name="Fn"></param>
        /// <returns></returns>
        public int CompanySet(CompanyEntity U)
        {
            int request = -1;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Company_Set", new object[] { U.ID, U.Name, U.Province, U.City, U.Address, U.Map, U.Introduce, U.Url, U.Tel, U.Email, U.Aptitude, U.Portrait, U.Rank }))
                {

                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : -1;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取公司信息
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public CompanyEntity CompanyByID(int UserID)
        {
            CompanyEntity request = new CompanyEntity();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Company_ByID", new object[] { UserID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.UserID = reader[1].ToInt32();
                        else
                            request.UserID = 0;
                        request.Name = reader[2].ToString();
                        request.Province = reader[3].ToString();
                        request.City = reader[4].ToString();
                        request.Address = reader[5].ToString();
                        request.Map = reader[6].ToString();
                        request.Tel = reader[7].ToString();
                        request.Email = reader[8].ToString();
                        request.Aptitude = reader[9].ToString();
                        request.Portrait = reader[10].ToString();
                        if (reader[11] != DBNull.Value)
                            request.Audit = reader[11].ToBoolean();
                        else
                            request.Audit = false;
                        if (reader[12] != DBNull.Value)
                            request.Rank = reader[12].ToInt32();
                        else
                            request.Rank = 0;
                        if (reader[13] != DBNull.Value)
                            request.CreateTime = reader[13].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        if (reader[14] != DBNull.Value)
                            request.Hits = reader[14].ToInt32();
                        else
                            request.Hits = 0;
                        request.Url = reader[15].ToString();
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 获取公司排序信息
        /// </summary>
        /// <param name="Filed"></param>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<CompanyEntity> CompanySort(string Filed, int Page, int PageSize, bool Desc, string Compel)
        {
            List<CompanyEntity> request = new List<CompanyEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Company_Sort", new object[] { Filed, Page, PageSize, Desc, Compel }))
                {

                    while (reader.Read())
                    {
                        CompanyEntity entity = new CompanyEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        entity.Name = reader[2].ToString();
                        entity.Province = reader[3].ToString();
                        entity.City = reader[4].ToString();
                        entity.Address = reader[5].ToString();
                        entity.Map = reader[6].ToString();
                        entity.Tel = reader[7].ToString();
                        entity.Email = reader[8].ToString();
                        entity.Aptitude = reader[9].ToString();
                        entity.Portrait = reader[10].ToString();
                        if (reader[11] != DBNull.Value)
                            entity.Audit = reader[11].ToBoolean();
                        else
                            entity.Audit = false;
                        if (reader[12] != DBNull.Value)
                            entity.Rank = reader[12].ToInt32();
                        else
                            entity.Rank = 0;
                        if (reader[13] != DBNull.Value)
                            entity.CreateTime = reader[13].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[14] != DBNull.Value)
                            entity.Hits = reader[14].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Url = reader[15].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        #endregion

        #region 关注/粉丝

        /// <summary>
        /// 创建关注
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int FocusSet(int UserID, int FocusID, bool IsDel)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Focus_Set", new object[] { UserID, FocusID, IsDel }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 关注粉丝列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="IsMe"></param>
        /// <returns></returns>
        public List<UserFocusEntity> FocusList(int UserID, bool IsMe)
        {
            List<UserFocusEntity> request = new List<UserFocusEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Focus_Q", new object[] { UserID, IsMe }))
                {
                    while (reader.Read())
                    {
                        UserFocusEntity entity = new UserFocusEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.FocusID = reader[2].ToInt32();
                        else
                            entity.FocusID = 0;
                        if (reader[3] != DBNull.Value)
                            entity.CreateTime = reader[3].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.FocusName = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.Score = reader[5].ToInt32();
                        else
                            entity.Score = 0;
                        if (reader[6] != DBNull.Value)
                            entity.CateID = reader[6].ToInt32();
                        else
                            entity.CateID = 0;
                        entity.Introduce = reader[7].ToString();
                        entity.Portrait = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.IsOpen = reader[9].ToBoolean();
                        else
                            entity.IsOpen = false;
                        if (reader[10] != DBNull.Value)
                            entity.FocusNum = reader[10].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[11] != DBNull.Value)
                            entity.FansNum = reader[11].ToInt32();
                        else
                            entity.FansNum = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 关注粉丝列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="IsMe"></param>
        /// <returns></returns>
        public List<UserFocusTEntity> FocusFans(int UserID)
        {
            List<UserFocusTEntity> request = new List<UserFocusTEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Focus_List]", new object[] { UserID }))
                {
                    while (reader.Read())
                    {
                        UserFocusTEntity entity = new UserFocusTEntity();                       
                        if (reader[0] != DBNull.Value)
                            entity.UserID = reader[0].ToInt32();
                        else
                            entity.UserID = 0;                        
                        entity.Name = reader[1].ToString();
                        entity.Cate = reader[2].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 关注粉丝列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="IsMe"></param>
        /// <returns></returns>
        public bool FocusHas(int UserID, int FocusID)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Focus_has", new object[] { UserID, FocusID }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 热门吧主
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="UserID"></param>
        /// <param name="Sort">默认根据粉丝数排行，1-时间</param>
        /// <param name="Desc"></param>
        /// <returns></returns>
        public List<UserFocusEntity> FocusSort(int PageSize, int PageIndex, int UserID, int Sort, bool Desc)
        {
            List<UserFocusEntity> request = new List<UserFocusEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Focus_Sort]", new object[] { PageSize, (PageIndex - 1) * PageSize, UserID, Sort, Desc }))
                {
                    while (reader.Read())
                    {
                        UserFocusEntity entity = new UserFocusEntity();
                        if (reader[0] != DBNull.Value)
                            entity.FocusID = reader[0].ToInt32();
                        else
                            entity.FocusID = 0;
                        if (reader[5] != DBNull.Value)
                        {
                            if (reader[5].ToInt32() == 2)
                            {

                                entity.FocusName = reader[8].ToString();
                            }
                            else
                            {
                                entity.FocusName = reader[1].ToString();
                            }
                        }
                        else
                        {
                            entity.FocusName = reader[1].ToString();
                        }
                        //entity.FocusName = entity.FocusName.Length > 7 ? entity.FocusName.Substring(0,6) : entity.FocusName;
                        entity.Portrait = reader[2].ToString();
                        if (reader[3] != DBNull.Value)
                            entity.FansNum = reader[3].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[4] != DBNull.Value)
                            entity.IfFocus = reader[4].ToInt32();
                        else
                            entity.IfFocus = 0;
                        if (reader[5] != DBNull.Value)
                        { entity.CateID = reader[5].ToInt32(); }
                        else
                            entity.CateID = 0;
                        if (reader[6] != DBNull.Value)
                            entity.IsOpen = reader[6].ToBoolean();
                        else
                            entity.IsOpen = false;
                        if (reader[7] != DBNull.Value)
                            entity.Score = reader[7].ToInt32();
                        else
                            entity.Score = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        #endregion

        #region 私信
        /// <summary>
        /// 创建私信
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int LetterInsert(int FromID, int ToID, string Text)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Letter_i", new object[] { FromID, ToID, Text }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 获取私信
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public ULetter LetterByID(int ID, int UserID)
        {
            ULetter request = new ULetter();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Letter_ByID", new object[] { ID, UserID }))
                {
                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        if (reader[1] != DBNull.Value)
                            request.FromID = reader[1].ToInt32();
                        else
                            request.FromID = 0;
                        if (reader[2] != DBNull.Value)
                            request.ToID = reader[2].ToInt32();
                        else
                            request.ToID = 0;
                        if (reader[3] != DBNull.Value)
                            request.CreateTime = reader[3].ToDateTime();
                        else
                            request.CreateTime = DateTime.Now;
                        request.Text = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            request.IsSee = reader[5].ToBoolean();
                        else
                            request.IsSee = false;

                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 删除私信
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public bool LetterDelete(int ID, int UserID)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Letter_Delete", new object[] { ID, UserID }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 私信列表
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<ULetter> Letter(int UserID, int Page, int PageSize, bool IsFrom)
        {
            List<ULetter> request = new List<ULetter>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Letter_Q", new object[] { UserID, Page, PageSize, IsFrom }))
                {

                    while (reader.Read())
                    {
                        ULetter entity = new ULetter();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.FromID = reader[1].ToInt32();
                        else
                            entity.FromID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.ToID = reader[2].ToInt32();
                        else
                            entity.ToID = 0;
                        entity.Text = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.CreateTime = reader[4].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;

                        if (reader[5] != DBNull.Value)
                            entity.IsSee = reader[5].ToBoolean();
                        else
                            entity.IsSee = false;
                        entity.Name = reader[6].ToString();
                        entity.Portrait = reader[7].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 手机查询私信列表
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<ULetter> PLetter(int UserID, string OpenTime, string EndTime, int PageSize, bool IsFrom)
        {
            List<ULetter> request = new List<ULetter>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Letter_PQ]", new object[] { UserID, OpenTime, EndTime, PageSize, IsFrom }))
                {

                    while (reader.Read())
                    {
                        ULetter entity = new ULetter();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.FromID = reader[1].ToInt32();
                        else
                            entity.FromID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.ToID = reader[2].ToInt32();
                        else
                            entity.ToID = 0;
                        entity.Text = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.CreateTime = reader[4].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;

                        if (reader[5] != DBNull.Value)
                            entity.IsSee = reader[5].ToBoolean();
                        else
                            entity.IsSee = false;
                        entity.Name = reader[6].ToString();
                        entity.Portrait = reader[7].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 创建私信
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int LetterSet(int ID, int UserID)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Letter_Set", new object[] { ID, UserID }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion

        #region 自选
        /// <summary>
        /// 创建自选
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UserID"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public int ChooseInsert(int UserID, int CenterID, string Code)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Choose_i", new object[] { UserID, CenterID, Code }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 是否已经自选
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UserID"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public bool ChooseHas(int UserID, int CenterID, string Code)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Choose_has", new object[] { UserID, CenterID, Code }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? (reader[0].ToInt32() > 0 ? true : false) : false;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 删除自选
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UserID"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public bool ChooseDelete(int UserID, int CenterID, string Code)
        {
            bool request = false;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Choose_Delete]", new object[] { UserID, CenterID, Code });
                request = true;
            }
            catch (Exception ex) { }
            return request;
        }

        /// <summary>
        /// 自选列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<UserCodeEntity> Choose(int UserID)
        {
            List<UserCodeEntity> request = new List<UserCodeEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Choose_Q", new object[] { UserID }))
                {

                    while (reader.Read())
                    {
                        UserCodeEntity entity = new UserCodeEntity();
                        if (reader[0] != DBNull.Value)
                            entity.UserID = reader[0].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[2].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 自选排行
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<Goods> ChooseSort(int Size)
        {
            List<Goods> request = new List<Goods>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Choose_Sort", new object[] { Size }))
                {

                    while (reader.Read())
                    {
                        Goods entity = new Goods();
                        if (reader[0] != DBNull.Value)
                            entity.CenterID = reader[0].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Code = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Stock = reader[2].ToInt32();
                        else
                            entity.Stock = 0;
                        entity.CenterName = reader[3].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion

        #region 开户
        /// <summary>
        /// 开户列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="UserName"></param>
        /// <param name="CenterID"></param>
        /// <param name="Sort"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<UOpen> OpenList(int PageSize, int PageIndex, string UserName, int CenterID,string Code, int Sort, bool Desc, bool IsDel)
        {
            List<UOpen> request = new List<UOpen>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Open_List]", new object[] { PageSize, (PageIndex - 1) * PageSize, UserName, CenterID, Code, Sort, Desc, IsDel }))
                {

                    while (reader.Read())
                    {
                        UOpen entity = new UOpen();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Url = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.UserID = reader[2].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[3] != DBNull.Value)
                            entity.CenterID = reader[3].ToInt32();
                        else
                            entity.CenterID = 0;
                        if (reader[4] != DBNull.Value)
                            entity.CreateTime = reader[4].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.UserName = reader[5].ToString();
                        entity.CenterName = reader[6].ToString();
                        entity.BourseWebSite = reader[7].ToString();
                        entity.BourseBank = reader[8].ToString();
                        entity.BourseOpenWeb = reader[9].ToString();
                        entity.BourseOpenWebRole = reader[10].ToString();
                        entity.BourseSoftUrl = reader[11].ToString();
                        entity.BourseImg = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.Bourseisopen = reader[13].ToBoolean();
                        else
                            entity.Bourseisopen = false;

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 开户总数
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int MOpenCount(string UserName = "", int CenterID = 0, string Code="", bool IsDel = false)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { UserName, CenterID, Code, IsDel };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Open_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }



        /// <summary>
        /// 开户列表
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<UOpen> Open(int UserID, bool IsDel)
        {
            List<UOpen> request = new List<UOpen>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Open_Q", new object[] { UserID, IsDel }))
                {

                    while (reader.Read())
                    {
                        UOpen entity = new UOpen();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.CenterID = reader[2].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[3].ToString();
                        entity.Url = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[6] != DBNull.Value)
                            entity.IsDel = reader[6].ToBoolean();
                        else
                            entity.IsDel = false;
                        entity.BourseWebSite = reader[7].ToString();
                        entity.BourseBank = reader[8].ToString();
                        entity.BourseOpenWeb = reader[9].ToString();
                        entity.BourseOpenWebRole = reader[10].ToString();
                        entity.BourseSoftUrl = reader[11].ToString();
                        entity.BourseImg = reader[12].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 设置开户
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int OpenSet(UOpen U)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Open_Set", new object[] { U.ID, U.UserID, U.CenterID, U.Url, U.IsDel }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 删除开户信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int DelOpen(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Open_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }

        }
        #endregion

        #region 模拟交易
        /// <summary>
        /// 新增交易
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="CenterID"></param>
        /// <param name="Code"></param>
        /// <param name="Amount"></param>
        /// <param name="CurPrice"></param>
        /// <returns></returns>
        public int TradInsert(int UserID, int CenterID, string CenterName, string Code, string Name, int Amount, decimal CurPrice, decimal Poundage)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Trad_i", new object[] { UserID, CenterID, CenterName, Code, Name, Amount, CurPrice, Poundage }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 可交易藏品
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<TardEntity> TradUsable(int UserID)
        {
            List<TardEntity> request = new List<TardEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Trad_Usable", new object[] { UserID }))
                {

                    while (reader.Read())
                    {
                        TardEntity entity = new TardEntity();
                        if (reader[0] != DBNull.Value)
                            entity.CenterID = reader[0].ToInt32();
                        else
                            entity.CenterID = 0;

                        entity.CenterName = reader[1].ToString();

                        entity.Code = reader[2].ToString();

                        entity.Fullname = reader[3].ToString();

                        if (reader[4] != DBNull.Value)
                            entity.Stock = reader[4].ToInt32();
                        else
                            entity.Stock = 0;
                        if (reader[5] != DBNull.Value)
                            entity.Ratio = reader[5].ToDecimal();
                        else
                            entity.Ratio = 0;

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 交易列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<TardEntity> TradList(int Page, int PageSize, int UserID)
        {
            List<TardEntity> entitys = new List<TardEntity>();

            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                object[] obj = new object[] { Page, PageSize, UserID };

                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Trad_List]", obj))
                {
                    TardEntity entity = null;
                    while (reader.Read())
                    {
                        entity = new TardEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.CenterID = reader[2].ToInt32();
                        else
                            entity.CenterID = 0;

                        entity.CenterName = reader[3].ToString();
                        entity.Code = reader[4].ToString();
                        entity.Fullname = reader[5].ToString();

                        if (reader[6] != DBNull.Value)
                            entity.Stock = reader[6].ToInt32();
                        else
                            entity.Stock = 0;

                        entity.OnLinePrice = reader[7].ToString();

                        if (reader[8] != DBNull.Value)
                            entity.UpdataTime = reader[8].ToDateTime();
                        else
                            entity.UpdataTime = DateTime.Now;

                        entitys.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entitys;
        }



        /// <summary>
        /// 手机查询交易列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<TardEntity> PTradList(string OpenTime,string EndTime, int PageSize, int UserID)
        {
            List<TardEntity> entitys = new List<TardEntity>();

            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                object[] obj = new object[] { OpenTime, EndTime,PageSize, UserID };

                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Trad_PList]", obj))
                {
                    TardEntity entity = null;
                    while (reader.Read())
                    {
                        entity = new TardEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.CenterID = reader[2].ToInt32();
                        else
                            entity.CenterID = 0;

                        entity.CenterName = reader[3].ToString();
                        entity.Code = reader[4].ToString();
                        entity.Fullname = reader[5].ToString();

                        if (reader[6] != DBNull.Value)
                            entity.Stock = reader[6].ToInt32();
                        else
                            entity.Stock = 0;

                        entity.OnLinePrice = reader[7].ToString();

                        if (reader[8] != DBNull.Value)
                            entity.UpdataTime = reader[8].ToDateTime();
                        else
                            entity.UpdataTime = DateTime.Now;

                        entitys.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entitys;
        }

        #endregion

        #region 会员点击排行，会员积分排行
        /// <summary>
        /// 会员点击排行 Filed= Hits || Score
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> UserSort(string Filed, int Size)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_User_Sort", new object[] { Filed, Size }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Score = reader[2].ToInt32();
                        else
                            entity.Score = 0;
                        if (reader[3] != DBNull.Value)
                            entity.CateID = reader[3].ToInt32();
                        else
                            entity.CateID = 0;

                        entity.Portrait = reader[4].ToString();

                        if (reader[5] != DBNull.Value)
                            entity.Hits = reader[5].ToInt32();
                        else
                            entity.Hits = 0;

                        entity.CateName = reader[6].ToString();

                        if (reader[7] != DBNull.Value)
                            entity.FansNum = reader[7].ToInt32();
                        else
                            entity.FansNum = 0;

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 机构排行
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> OrgSort(string Filed, int Page, int PageSize, string Province, string City)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_CompanySort", new object[] { Filed, Page, PageSize, Province, City }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Province = reader[2].ToString();
                        entity.City = reader[3].ToString();
                        entity.Address = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Portrait = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Hits = reader[7].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.CateName = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.FocusNum = reader[9].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[10] != DBNull.Value)
                            entity.FansNum = reader[10].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[11] != DBNull.Value)
                            entity.BarNum = reader[11].ToInt32();
                        else
                            entity.BarNum = 0;
                        entity.Company = reader[12].ToString();
                        entity.CompanyInfo = reader[13].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 机构排行
        /// </summary>
        /// <param name="Filed"></param>
        /// <param name="CompanyName">可根据公司名模糊查询</param>
        /// <returns></returns>
        public List<User> OrgSortByCompany(string Filed, int Page, int PageSize, string Province, string City, string CompanyName)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_CompanySort_Q]", new object[] { Filed, Page, PageSize, Province, City, CompanyName }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Province = reader[2].ToString();
                        entity.City = reader[3].ToString();
                        entity.Address = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Portrait = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Hits = reader[7].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.CateName = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.FocusNum = reader[9].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[10] != DBNull.Value)
                            entity.FansNum = reader[10].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[11] != DBNull.Value)
                            entity.BarNum = reader[11].ToInt32();
                        else
                            entity.BarNum = 0;
                        entity.Company = reader[12].ToString();
                        entity.CompanyInfo = reader[13].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }



        /// <summary>
        /// 机构排行
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> POrgSort(string Filed, string OpenTime, string EndTime, int PageSize, string Province, string City)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_CompanySort_PQ", new object[] { Filed, OpenTime, EndTime, PageSize, Province, City }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Province = reader[2].ToString();
                        entity.City = reader[3].ToString();
                        entity.Address = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Portrait = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Hits = reader[7].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.CateName = reader[8].ToString();
                        if (reader[9] != DBNull.Value)
                            entity.FocusNum = reader[9].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[10] != DBNull.Value)
                            entity.FansNum = reader[10].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[11] != DBNull.Value)
                            entity.BarNum = reader[11].ToInt32();
                        else
                            entity.BarNum = 0;
                        entity.Company = reader[12].ToString();
                        entity.CompanyInfo = reader[13].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 机构排行
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> OrgSaerch(string Filed, int Page, int PageSize, int CenterID)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_CompanySearch", new object[] { Filed, Page, PageSize, CenterID }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Province = reader[2].ToString();
                        entity.City = reader[3].ToString();
                        entity.Address = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Portrait = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Hits = reader[7].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[8] != DBNull.Value)
                            entity.FocusNum = reader[8].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[9] != DBNull.Value)
                            entity.FansNum = reader[9].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[10] != DBNull.Value)
                            entity.BarNum = reader[10].ToInt32();
                        else
                            entity.BarNum = 0;
                        entity.Company = reader[11].ToString();
                        entity.CompanyInfo = reader[12].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 机构排行
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> POrgSaerch(string Filed, string OpenTime, string EndTime, int PageSize, int CenterID)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_CompanySearch_PQ", new object[] { Filed, OpenTime, EndTime, PageSize, CenterID }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        entity.Province = reader[2].ToString();
                        entity.City = reader[3].ToString();
                        entity.Address = reader[4].ToString();
                        if (reader[5] != DBNull.Value)
                            entity.CreateTime = reader[5].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.Portrait = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.Hits = reader[7].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[8] != DBNull.Value)
                            entity.FocusNum = reader[8].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[9] != DBNull.Value)
                            entity.FansNum = reader[9].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[10] != DBNull.Value)
                            entity.BarNum = reader[10].ToInt32();
                        else
                            entity.BarNum = 0;
                        entity.Company = reader[11].ToString();
                        entity.CompanyInfo = reader[12].ToString();

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion

        #region 收藏
        /// <summary>
        /// 收藏列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Order">根据时间排序</param>
        /// <param name="UserID"></param>
        /// <param name="BarID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<Bar> CollBarList(int PageSize, int Page, int Order, int UserID, int BarID, bool IsDel)
        {
            List<Bar> entitys = new List<Bar>();

            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                object[] obj = new object[] { PageSize, (Page - 1) * PageSize, Order, UserID, BarID, IsDel };

                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_CollectBar_Q]", obj))
                {
                    Bar entity = null;
                    while (reader.Read())
                    {
                        entity = new Bar();
                        if (reader[0] != DBNull.Value)
                            entity.CollID = reader[0].ToInt32();
                        else
                            entity.CollID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.ID = reader[2].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[3] != DBNull.Value)
                            entity.Type = reader[3].ToInt32();
                        else
                            entity.Type = 0;
                        entity.Text = reader[4].ToString();
                        //entity.LableT = reader[5].ToString();
                        entity.CreateTime = reader[6].ToDateTime();
                        if (reader[7] != DBNull.Value)
                            entity.Discuss = reader[7].ToInt32();
                        else
                            entity.Discuss = 0;
                        if (reader[8] != DBNull.Value)
                            entity.Goods = reader[8].ToInt32();
                        else
                            entity.Goods = 0;
                        if (reader[9] != DBNull.Value)
                            entity.OptInID = reader[9].ToInt32();
                        else
                            entity.OptInID = 0;
                        entity.Name = reader[10].ToString();
                        entity.CenterID = reader[11].ToString();
                        entity.Code = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.Come = reader[13].ToInt32();
                        else
                            entity.Come = 0;
                        if (reader[14] != DBNull.Value)
                            entity.IsTv = reader[14].ToBoolean();
                        else
                            entity.IsTv = false;
                        entity.Portrait = reader[15].ToString();
                        entity.Img = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            entity.REID = reader[17].ToInt32();
                        else
                            entity.REID = 0;
                        if (reader[18] != DBNull.Value)
                            entity.RECate = reader[18].ToInt32();
                        else
                            entity.RECate = 0;
                        entity.RETitle = reader[19].ToString();
                        entity.RESmallTitle = reader[20].ToString();
                        if (reader[21] != DBNull.Value)
                            entity.RECreateTime = reader[21].ToDateTime();
                        else
                            entity.RECreateTime = DateTime.Now;
                        entity.REUrl = reader[22].ToString();
                        if (reader[23] != DBNull.Value)
                            entity.ReHits = reader[23].ToInt32();
                        else
                            entity.ReHits = 0;
                        if (reader[24] != DBNull.Value)
                            entity.ReTotal = reader[24].ToInt32();
                        else
                            entity.ReTotal = 0;
                        if (reader[25] != DBNull.Value)
                            entity.TranTotal = reader[25].ToInt32();
                        else
                            entity.TranTotal = 0;
                        if (reader[26] != DBNull.Value)
                            entity.RowNumber = reader[26].ToInt32();
                        else
                            entity.RowNumber = -1;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entitys;
        }

        /// <summary>
        /// 手机查询收藏列表
        /// </summary>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="Order">根据时间排序</param>
        /// <param name="UserID"></param>
        /// <param name="BarID"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public static List<Bar> PCollBarList(string OpenTime,string EndTime,int PageSize,  int Order, int UserID, int BarID, bool IsDel)
        {
            List<Bar> entitys = new List<Bar>();

            try
            {

                SQLHelper sqlHelp = new SQLHelper();
                object[] obj = new object[] { OpenTime, EndTime, PageSize, Order, UserID, BarID, IsDel };

                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_N_CollectBar_PQ]", obj))
                {
                    Bar entity = null;
                    while (reader.Read())
                    {
                        entity = new Bar();
                        if (reader[0] != DBNull.Value)
                            entity.CollID = reader[0].ToInt32();
                        else
                            entity.CollID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.ID = reader[2].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[3] != DBNull.Value)
                            entity.Type = reader[3].ToInt32();
                        else
                            entity.Type = 0;
                        entity.Text = reader[4].ToString();
                        //entity.LableT = reader[5].ToString();
                        entity.CreateTime = reader[6].ToDateTime();
                        if (reader[7] != DBNull.Value)
                            entity.Discuss = reader[7].ToInt32();
                        else
                            entity.Discuss = 0;
                        if (reader[8] != DBNull.Value)
                            entity.Goods = reader[8].ToInt32();
                        else
                            entity.Goods = 0;
                        if (reader[9] != DBNull.Value)
                            entity.OptInID = reader[9].ToInt32();
                        else
                            entity.OptInID = 0;
                        entity.Name = reader[10].ToString();
                        entity.CenterID = reader[11].ToString();
                        entity.Code = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.Come = reader[13].ToInt32();
                        else
                            entity.Come = 0;
                        if (reader[14] != DBNull.Value)
                            entity.IsTv = reader[14].ToBoolean();
                        else
                            entity.IsTv = false;
                        entity.Portrait = reader[15].ToString();
                        entity.Img = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            entity.REID = reader[17].ToInt32();
                        else
                            entity.REID = 0;
                        if (reader[18] != DBNull.Value)
                            entity.RECate = reader[18].ToInt32();
                        else
                            entity.RECate = 0;
                        entity.RETitle = reader[19].ToString();
                        entity.RESmallTitle = reader[20].ToString();
                        if (reader[21] != DBNull.Value)
                            entity.RECreateTime = reader[21].ToDateTime();
                        else
                            entity.RECreateTime = DateTime.Now;
                        entity.REUrl = reader[22].ToString();
                        if (reader[23] != DBNull.Value)
                            entity.ReHits = reader[23].ToInt32();
                        else
                            entity.ReHits = 0;
                        if (reader[24] != DBNull.Value)
                            entity.ReTotal = reader[24].ToInt32();
                        else
                            entity.ReTotal = 0;
                        if (reader[25] != DBNull.Value)
                            entity.TranTotal = reader[25].ToInt32();
                        else
                            entity.TranTotal = 0;
                        if (reader[26] != DBNull.Value)
                            entity.RowNumber = reader[26].ToInt32();
                        else
                            entity.RowNumber = -1;
                        entitys.Add(entity);
                    }

                    reader.Close();
                }

            }
            catch (Exception ex)
            {
            }
            return entitys;
        }

        /// <summary>
        /// 收藏邮吧
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int CollectBar(CollectBar entity)
        {
            try
            {
                object[] whereInfo = new object[] { entity.UserID, entity.BarID, entity.LableT, entity.CreateTime };
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_CollectBar_A]", whereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 取消收藏
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int UnCollect(int barID, int UserId)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_CollectBar_D]", new object[] { barID, UserId });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        #endregion

        #region 点赞
        /// <summary>
        /// 点赞
        /// </summary>
        /// <param name="usreid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int clickCon(int usreid, int id)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_Bar_Con]", new object[] { usreid, id });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;

            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 取消点赞
        /// </summary>
        /// <param name="usreid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int clickNoCon(int usreid, int id)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_N_Bar_NoCon]", new object[] { usreid, id });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;

            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion

        #region 活动
        /// <summary>
        /// 设置开户
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int ActivitySet(Activity U)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Activity_Set", new object[] { U.ID, U.CenterID, U.CenterName, U.Title, U.SmallTitle, U.Img, U.Text, U.UserID, U.Cate,U.OutDateTime }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 活动
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public Activity ActivityByID(int ID)
        {
            Activity entity = new Activity();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Activity_ByID", new object[] { ID }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Title = reader[3].ToString();
                        entity.SmallTitle = reader[4].ToString();
                        entity.Img = reader[5].ToString();
                        entity.Text = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[8] != DBNull.Value)
                            entity.UserID = reader[8].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Name = reader[10].ToString();
                        entity.Company = reader[11].ToString();
                        entity.Cate = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.OutDate = reader[13].ToBoolean();
                        else
                            entity.OutDate = false;
                        if (reader[14] != DBNull.Value)
                            entity.OutDateTime = reader[14].ToDateTime();
                        else
                            entity.OutDateTime = DateTime.Now;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entity;
        }

        /// <summary>
        /// 活动列表
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public List<Activity> Activity(int UserID, int Page, int PageSize)
        {
            List<Activity> request = new List<Activity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Activity_Q", new object[] { UserID, Page, PageSize }))
                {

                    while (reader.Read())
                    {
                        Activity entity = new Activity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Title = reader[3].ToString();
                        entity.SmallTitle = reader[4].ToString();
                        entity.Img = reader[5].ToString();
                       // entity.Text = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[8] != DBNull.Value)
                            entity.UserID = reader[8].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Name = reader[10].ToString();
                        entity.Company = reader[11].ToString();
                        entity.Cate = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.OutDate = reader[13].ToBoolean();
                        else
                            entity.OutDate = false;
                        if (reader[14] != DBNull.Value)
                            entity.OutDateTime = reader[14].ToDateTime();
                        else
                            entity.OutDateTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 可根据交易所查询活动列表
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public List<Activity> ActivityByCenter(int UserID, int Page, int PageSize, int CenterID, int Order, bool Desc)
        {
            List<Activity> request = new List<Activity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Activity_QByCenter]", new object[] { UserID, Page, PageSize, CenterID, Order, Desc }))
                {

                    while (reader.Read())
                    {
                        Activity entity = new Activity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Title = reader[3].ToString();
                        entity.SmallTitle = reader[4].ToString();
                        entity.Img = reader[5].ToString();
                        // entity.Text = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[8] != DBNull.Value)
                            entity.UserID = reader[8].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Name = reader[10].ToString();
                        entity.Company = reader[11].ToString();
                        entity.Cate = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.OutDate = reader[13].ToBoolean();
                        else
                            entity.OutDate = false;
                        if (reader[14] != DBNull.Value)
                            entity.OutDateTime = reader[14].ToDateTime();
                        else
                            entity.OutDateTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 手机查询活动列表
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public List<Activity> PActivity(int UserID, string OpenTime, string EndTime, int PageSize)
        {
            List<Activity> request = new List<Activity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Activity_PQ", new object[] { UserID, OpenTime, EndTime, PageSize }))
                {

                    while (reader.Read())
                    {
                        Activity entity = new Activity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Title = reader[3].ToString();
                        entity.SmallTitle = reader[4].ToString();
                        entity.Img = reader[5].ToString();
                        entity.Text = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[8] != DBNull.Value)
                            entity.UserID = reader[8].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Name = reader[10].ToString();
                        entity.Company = reader[11].ToString();
                        entity.Cate = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.OutDate = reader[13].ToBoolean();
                        else
                            entity.OutDate = false;
                        if (reader[14] != DBNull.Value)
                            entity.OutDateTime = reader[14].ToDateTime();
                        else
                            entity.OutDateTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 后台查询活动列表
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public List<Activity> MActivity(int UserID, int Page, int PageSize,int Order ,bool Desc)
        {
            List<Activity> request = new List<Activity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Activity_MQ]", new object[] { UserID, Page, PageSize, Order, Desc }))
                {

                    while (reader.Read())
                    {
                        Activity entity = new Activity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.CenterID = reader[1].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[2].ToString();
                        entity.Title = reader[3].ToString();
                        entity.SmallTitle = reader[4].ToString();
                        entity.Img = reader[5].ToString();
                        entity.Text = reader[6].ToString();
                        if (reader[7] != DBNull.Value)
                            entity.CreateTime = reader[7].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[8] != DBNull.Value)
                            entity.UserID = reader[8].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[9] != DBNull.Value)
                            entity.Hits = reader[9].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Name = reader[10].ToString();
                        entity.Company = reader[11].ToString();
                        entity.Cate = reader[12].ToString();
                        if (reader[13] != DBNull.Value)
                            entity.OutDate = reader[13].ToBoolean();
                        else
                            entity.OutDate = false;
                        if (reader[14] != DBNull.Value)
                            entity.OutDateTime = reader[14].ToDateTime();
                        else
                            entity.OutDateTime = DateTime.Now;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 活动总数
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static int ActivityCount(int UserID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { UserID };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Activity_MC]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        /// <summary>
        /// 后台删除活动
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int DelActivity(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Activity_D]", ID);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 活动删除
        /// </summary>
        /// <param name="U"></param>
        /// <returns></returns>
        public int ActivityDel(int ID, int UserID)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Activity_Del", new object[] { ID, UserID }))
                {
                    //while (reader.Read())
                    //{
                    //    request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    //}
                    reader.Close();
                }
                request = 1;
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 活动过期
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UserID"></param>
        /// <param name="OutDate"></param>
        /// <returns></returns>
        public int ActivityOutDate(int ID, int UserID,bool OutDate)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Activity_OutDate]", new object[] { ID, UserID, OutDate });
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// 活动交易所
        /// </summary>
        /// <returns></returns>
        public List<NewsBourseGroupEntity> BourseGroup()
        {
            List<NewsBourseGroupEntity> request = new List<NewsBourseGroupEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_UA_Bourse]", new object[] { }))
                {

                    while (reader.Read())
                    {
                        NewsBourseGroupEntity entity = new NewsBourseGroupEntity();
                        if (reader[0] != DBNull.Value)
                            entity.CenterID = reader[0].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.Shortened = reader[1].ToString();
                        entity.Name = reader[2].ToString();
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        #endregion

        #region 分析师
        /// <summary>
        /// 申请绑定
        /// </summary>
        /// <returns></returns>
        public int Underling(int UID, int UserID)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Underling_a", new object[] { UID, UserID }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 状态
        /// </summary>
        /// <returns></returns>
        public int UnderlingState(int UID, int UserID)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Underling_s", new object[] { UID, UserID }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 会员点击排行 Filed= Hits || Score
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> UnderlingList(int UID)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Underling_Q", new object[] { UID }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Score = reader[2].ToInt32();
                        else
                            entity.Score = 0;
                        entity.Portrait = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.FocusNum = reader[5].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[6] != DBNull.Value)
                            entity.FansNum = reader[6].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[7] != DBNull.Value)
                            entity.BarNum = reader[7].ToInt32();
                        else
                            entity.BarNum = 0;
                        if (reader[8] != DBNull.Value)
                            entity.UnderlingState = reader[8].ToInt32();
                        else
                            entity.UnderlingState = 0;
                        entity.Introduce = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            entity.UnderlingID = reader[10].ToInt32();
                        else
                            entity.UnderlingID = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        
        /// <summary>
        /// 申请绑定
        /// </summary>
        /// <returns></returns>
        public int UnderlingSet(int ID, int UserID, bool Fn)
        {
            int request = 0;
            try
            {
                int sta = Fn == true ? 2 : 0;
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Underling_action", new object[] { ID, UserID, sta }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 分析师列表
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="Where">邮箱或者手机号</param>
        /// <param name="Order"></param>
        /// <param name="Desc"></param>
        /// <param name="IsDel"></param>
        /// <returns></returns>
        public List<AnalystEntity> AnalystList(int PageIndex, int PageSize, string Where, int UserID, int Order, bool Desc, bool IsDel)
        {
            List<AnalystEntity> request = new List<AnalystEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Analyst]", new object[] { PageSize, (PageIndex - 1) * PageSize, Where, UserID, Order, Desc, IsDel }))
                {
                    while (reader.Read())
                    {
                        AnalystEntity entity = new AnalystEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Sex = reader[2].ToBoolean();
                        else
                            entity.Sex = false;
                        entity.CardNO = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.Score = reader[4].ToInt32();
                        else
                            entity.Score = 0;
                        entity.Introduce = reader[5].ToString();
                        entity.Tel = reader[6].ToString();
                        entity.Address = reader[7].ToString();
                        if (reader[8] != DBNull.Value)
                            entity.IsDel = reader[8].ToBoolean();
                        else
                            entity.IsDel = false;
                        entity.Portrait = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            entity.Money = reader[10].ToInt32();
                        else
                            entity.Money = 0;
                        if (reader[11] != DBNull.Value)
                            entity.Hits = reader[11].ToInt32();
                        else
                            entity.Hits = 0;
                        entity.Company = reader[12].ToString();
                        entity.CompanyInfo = reader[13].ToString();
                        entity.Province = reader[14].ToString();
                        entity.City = reader[15].ToString();
                        if (reader[16] != DBNull.Value)
                            entity.IsBroker = reader[16].ToInt32();
                        else
                            entity.IsBroker = 0;
                        if (reader[17] != DBNull.Value)
                            entity.IsInvite = reader[17].ToInt32();
                        else
                            entity.IsInvite = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 经济商邀请分析师
        /// </summary>
        /// <returns></returns>
        public int UnderlingAdd(int UID, int UserID, int Fn)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Underling_Set]", new object[] { UID, UserID, Fn }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 通过申请
        /// </summary>
        /// <param name="UID">分析师</param>
        /// <param name="UserID">经济商</param>
        /// <param name="Fn"></param>
        /// <returns></returns>
        public int UnderlingPass(int ID, int UID, int UserID, int Fn)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Underling_Pass]", new object[] {ID, UID, UserID, Fn }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 分析师被谁邀请
        /// </summary>
        /// <param name="Filed"></param>
        /// <returns></returns>
        public List<User> UnderlingAnalyst(int UID)
        {
            List<User> request = new List<User>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_U_Underling_AQ]", new object[] { UID }))
                {
                    while (reader.Read())
                    {
                        User entity = new User();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.Name = reader[1].ToString();
                        if (reader[2] != DBNull.Value)
                            entity.Score = reader[2].ToInt32();
                        else
                            entity.Score = 0;
                        entity.Portrait = reader[3].ToString();
                        if (reader[4] != DBNull.Value)
                            entity.Hits = reader[4].ToInt32();
                        else
                            entity.Hits = 0;
                        if (reader[5] != DBNull.Value)
                            entity.FocusNum = reader[5].ToInt32();
                        else
                            entity.FocusNum = 0;
                        if (reader[6] != DBNull.Value)
                            entity.FansNum = reader[6].ToInt32();
                        else
                            entity.FansNum = 0;
                        if (reader[7] != DBNull.Value)
                            entity.BarNum = reader[7].ToInt32();
                        else
                            entity.BarNum = 0;
                        if (reader[8] != DBNull.Value)
                            entity.UnderlingState = reader[8].ToInt32();
                        else
                            entity.UnderlingState = 0;
                        entity.Introduce = reader[9].ToString();
                        if (reader[10] != DBNull.Value)
                            entity.UnderlingID = reader[10].ToInt32();
                        else
                            entity.UnderlingID = 0;
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        #endregion

        #region 后台 
        public static MUser MUserLogin(string UserName, string PassWord)
        {
            string Pass = new UserDA().CreatePass(PassWord);
            MUser request = new MUser();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_M_User_Login", new object[] { UserName, Pass }))
                {

                    while (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                            request.ID = reader[0].ToInt32();
                        else
                            request.ID = 0;
                        request.UserName = reader[1].ToString();
                        request.PassWord = reader[2].ToString();
                        if (reader[3] != DBNull.Value)
                            request.Cate = reader[3].ToInt32();
                        else
                            request.Cate = 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }

        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Detail"></param>
        /// <returns></returns>
        public static int MLogAdd(int UserID, string Name, string Detail, string Remarl)
        {
            int request = 0;
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_M_Log_A]", new object[] { UserID, Name, Detail, Remarl }))
                {
                    while (reader.Read())
                    {
                        request = reader[0] != DBNull.Value ? reader[0].ToInt32() : 0;
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        ///修改后台密码
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="Pwd"></param>
        /// <param name="NewPwd"></param>
        /// <returns></returns>
        public static int UpdateMPwd(int UserID, string Pwd, string NPwd)
        {
            string Pwds = new UserDA().CreatePass(Pwd);
            string NPwds = new UserDA().CreatePass(NPwd);
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { UserID, Pwds, NPwds };
                object obj = sqlHelp.ExecuteSPScalar("[sp_M_User_Pwd]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return -1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        #endregion

        #region 委托
        /// <summary>
        /// 委托
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<UserEntrustEntity> UEntrustList(int UserID)
        {
            List<UserEntrustEntity> request = new List<UserEntrustEntity>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Entrust_Q", new object[] { UserID }))
                {

                    while (reader.Read())
                    {
                        UserEntrustEntity entity = new UserEntrustEntity();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.CenterID = reader[2].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[3].ToString();
                        entity.Code = reader[4].ToString();
                        entity.Name = reader[5].ToString();
                        if (reader[6] != DBNull.Value)
                            entity.Amount = reader[6].ToInt32();
                        else
                            entity.Amount = 0;
                        if (reader[7] != DBNull.Value)
                            entity.CurPrice = reader[7].ToDecimal();
                        else
                            entity.CurPrice = 0;
                        if (reader[8] != DBNull.Value)
                            entity.CreateTime = reader[8].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[9] != DBNull.Value)
                            entity.IsFinish = reader[9].ToInt32();
                        else
                            entity.IsFinish = 0;
                        if (reader[10] != DBNull.Value)
                            entity.Isbuy = reader[10].ToBoolean();
                        else
                            entity.Isbuy = true;
                        if (reader[11] != DBNull.Value)
                            entity.Poundage = reader[11].ToDecimal();
                        else
                            entity.Poundage = 0; 
                         if (reader[12] != DBNull.Value)
                             entity.LastPrice = reader[12].ToDecimal();
                        else
                             entity.LastPrice = 0;
                     
                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }


        /// <summary>
        /// 委托
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public List<UStock> UStockList(int UserID)
        {
            List<UStock> request = new List<UStock>();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("sp_U_Stock_Q", new object[] { UserID }))
                {

                    while (reader.Read())
                    {
                        UStock entity = new UStock();
                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        if (reader[1] != DBNull.Value)
                            entity.UserID = reader[1].ToInt32();
                        else
                            entity.UserID = 0;
                        if (reader[2] != DBNull.Value)
                            entity.CenterID = reader[2].ToInt32();
                        else
                            entity.CenterID = 0;
                        entity.CenterName = reader[3].ToString();
                        entity.Code = reader[4].ToString();
                        entity.Name = reader[5].ToString();
                        if (reader[6] != DBNull.Value)
                            entity.Amount = reader[6].ToInt32();
                        else
                            entity.Amount = 0;
                        if (reader[7] != DBNull.Value)
                            entity.CurPrice = reader[7].ToDecimal();
                        else
                            entity.CurPrice = 0;
                        if (reader[8] != DBNull.Value)
                            entity.CreateTime = reader[8].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        if (reader[9] != DBNull.Value)
                            entity.PowerMoney = reader[9].ToDecimal();
                        else
                            entity.PowerMoney = 0;

                        request.Add(entity);
                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return request;
        }




        /// <summary>
        /// 委托[买]
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UEntrustBuy(UserEntrustEntity entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { entity.ID, entity.UserID, entity.CenterID, entity.CenterName, entity.Code, entity.Name, entity.Amount, entity.CurPrice, entity.LastPrice, entity.CreateTime, entity.IsFinish, entity.Isbuy };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_Buy]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 委托[卖]
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UEntrustSell(UserEntrustEntity entity)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { entity.ID, entity.UserID, entity.CenterID, entity.CenterName, entity.Code, entity.Name, entity.Amount, entity.CurPrice, entity.LastPrice, entity.IsFinish, entity.Isbuy };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_Sell]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 委托是否完成
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsFinish">true-买,false-卖</param>
        /// <returns></returns>
        public int UEntrusStock(int ID, int UserID, bool IsFinish, DateTime CreateTime)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { ID, UserID, IsFinish, CreateTime };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_Stock]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 委托完成
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="IsFinish">true-买,false-卖</param>
        /// <returns></returns>
        public int UEntrusStockSuc(int ID, decimal LastPrice, DateTime CreateTime)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { ID, LastPrice, CreateTime };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_StockW]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 删除委托
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int UEntrustDel(int ID)
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                object[] tiaoj = new object[] { ID };
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_D]", tiaoj);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }


        /// <summary>
        /// 清空委托表
        /// </summary>
        /// <returns></returns>
        public int UEntrusClear()
        {
            try
            {
                SQLHelper sqlHelp = new SQLHelper();              
                object obj = sqlHelp.ExecuteSPScalar("[sp_U_Entrust_Clear]");
                return 1;
            }
            catch (Exception ex)
            {
                return 0;
            }
 
        }

        #endregion
    }
}
